var MessagepopMediator = Objs("view.MessagepopMediator",
	Mediator,
{

	initialize: function( name, viewComponent )
	{ 
		MessagepopMediator.$super.initialize.call( this, name, viewComponent );
    	this.VProxy = this.facade.retrieveProxy( ProxyNames.VEHICLE_PROXY );
		this.registerListeners();
	
		
	},
	registerListeners: function()
	{  
	 var mesPageView = this.get();
		mesPageView.addEventListener( MessagepopPage.ADD_CORRESPONDENCE, this.addCommentHandler, this );
	},
	get: function()
	{
		return this.viewComponent;
	},
	addCommentHandler: function()
	{ 
		if(document.getElementById("correspond_text").value)
		{
			var cMessage=new Object();
			cMessage.message = document.getElementById("correspond_text").value;
			this.VProxy.addInfoComment(cMessage);
			document.getElementById("correspond_text").value="";
		}
		else
		{
			alert("Comment box is empty. Please add some comments");
		}
	},
		listNotificationInterests: function()
	{
		return [
				NotificationNames.ADD_MESSAGE_SUCCESS,
				NotificationNames.LIST_MESSAGE
		];
	},
    handleNotification: function( note )
	{ 
		
		switch (note.getName() )
		{ 
				case NotificationNames.ADD_MESSAGE_SUCCESS:
			
				var messages=note.getBody().message;
				
				this.setmesvalue(messages);	
				break;
				case NotificationNames.LIST_MESSAGE:
			
				var messages=note.getBody().message;
				
				this.setmesvalue(messages);	
				break;
		}
	},
	setmesvalue:function(messages)
	{
		document.getElementById("model-poplist").innerHTML = '';
		var meshtml=''
		for(var i=0;i<messages.length;i++)
		{ 
			 meshtml+="<div class='commentBox'> <div id=messagehead style='border-bottom:solid 1px #CCC'><strong>On " +messages[i].dateTime+ " " +messages[i].messageOwener+ " Wrote</strong></div><div id=messagedetail style='padding-bottom:10px;'>" +messages[i].message+ "</div></div>"; 
		}
		
		document.getElementById("model-poplist").innerHTML = meshtml;
		
	},
	
});

